<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	//设置供应商信息
	function set_provider(id,data)
	{
		$("#price_"+id).val(data[0]);
		$("#delivery_"+id).val(data[1]);
	}

	$('select[name="supplier_id[]"]').change(function(){

		var pre = 'supplier_';
		var id = $(this).attr('id').substr(pre.length);
		//alert(id);
		var sku = $('#sku_'+id).val();
		//alert(sku);
		var providerid = $(this).val();
		//alert(providerid);
		
		$.ajax({		
			type:'post',
			url:'<?php echo url::base(true)?>p/warning/getproviderproducts',
			dataType:'json',
			data:{"providerid":providerid,"sku":sku},
			async:false,
			success:function(data)
			{
				if(data != false)
				{
					set_provider(id,data);
				}
			},
			error:function()
			{
				alert('error');
			}
		});
	});

	//自动提交
	$('#j_wdate').change(function(){

// 		$('#sel_form').submit();
		$('#sel_submit').click();
	});
	
});
</script>

								
								
<div class="" id="">

<form action="<?php echo url::base(true)?>p/warning/lists" method="get" id="sel_form">
<select name= "waringdate_sel" class="input-medium" id="j_wdate">
<option value="0">当日预警</option>
<option value="3">三日预警</option>
<option value="all">全部预警</option>
</select>
<span>sku
<input type="text" placeholder="" name="sku" class="input-medium"></span>
<span>预警数量大于
<input type="text" placeholder="" class="input-mini" name="miniwaring"></span>
<span>小于
<input type="text" placeholder="" class="input-mini" name="maxwarning"></span>
<span>采购人ID
<input type="text" placeholder="" class="input-mini" name="userid"></span>
<button type="submit" class="btn btn-info" id="sel_submit">查询</button>
</form>
<?php if(true){?>
<span>当前采购人员XXX</span>
<span>总共有<?php if(isset($total_count)){
	echo $total_count;
}else { echo '----';
};?>条SKU预警信息</span>
<!-- <button  class="btn btn-info" id="refash_warning">刷新预警</button> -->
<!-- <button  class="btn btn-info">刷新销量</button> -->
<?php }?>

<table class="table table-bordered">
<tbody>
<?php if(isset($skulists)){
foreach ($skulists as $sku){
?>
												<tr>
														<th>
															序号
														</th>
														<th>
															SKU
														</th>
														<th>
															中文名称
														</th>
														<th>
															成本
														</th>
														<th>
															税率
														</th>
														<th>
															实际可用库存
														</th>
														<th>
															在途库存
														</th>
													</tr>
													
													<tr>
														<td id="sel_<?php echo $sku['id']?>">
															<?php ?>
														</td>
														<td>
														<!-- SKU -->
															<input type="hidden" name="sku[]" 
															id="sku_<?php echo $sku['id'];?>"
															value="<?php echo $sku['sku']?>">
															<a href=""><?php echo $sku['sku']?></a>
														</td>
														<td>
														<!-- 名称 -->
														<input type="hidden" name="sku_name[]" value="">
															名称xxx
														</td>
														<td>
														<!-- 成本 -->
														<input type="hidden" name="sku_value[]" value="">
															10
														</td>
														<td>
														<!-- 税率 -->
															<input type="hidden" name="tax_rate[]" value="">
															17%
														</td>
														<td>
														<!-- 实际可用库存 -->
															<?php echo $sku['inventory_actual'];?>
														</td>
														<td>
														<!-- 在途库存 -->
															<?php echo $sku['inventory_onway'];?>
														</td>
												
												</tr>										
													<tr>
													<th>
															最佳下单日期
														</th>
													<th>
															预警数量
														</th>
														<th>
															大单数量
														</th>
														<th>
															日均销量
														</th>
														<th>
															7日销量
														</th>
														
														<th>
															可支持天数
														</th>
														
														<th>
															误差
														</th>
														
													</tr>
													
													<tr>
														<td>													
															<!-- 最佳下单日期 -->
															<?php 
															//可支持天数
															$supp_day = ($sku['inventory_actual'] + $sku['inventory_onway'])/$sku['daysales']
															- 3;
															$best = $supp_day - $sku['delivery'];?>
															
															<!-- 默认最佳下单日期-->															
															<span id="best_<?php echo $sku['id']?>">
															<?php 
															echo date('Y-m-d',strtotime('+'.ceil($best).'days'));
															?>
															</span>
														</td>
														
														<td>
														<!-- 预警数量() -->	
														<?php echo $sku['warning_quantity'];?>
														</td>
														<td>
														<!-- 大单数量 -->
														<?php echo $sku['warning_quantity'];?>
														</td>
														<td>
														   <!-- 日均销量 -->
															<span id="daysale_<?php echo $sku['id']?>">
															<?php echo $sku['daysales'];?></span>
														</td>
														<td>
														
														</td>
														<td>
															<span id="u_<?php echo $sku['id'];?>">
															<!-- 可支持天数 -->
															<?php echo round($supp_day,2)?>
															</span>
														</td>
														<td>
															<span id="m_<?php echo $sku['id'];?>">
															<!-- 误差 -->
															<?php echo round($sku['delivery'] - $supp_day,2);?>
															</span>
														</td>
														
												</tr>
												
												<tr>
														<th>
															供应商
														</th>
														<th>
															价格
														</th>
														<th>
															交货日期
														</th>
														<th>
															采购人
														</th>
														
													</tr>
												<tr>
														<td>
														<?php 
														//查找供应商
														$providers  = DB::select('erp_provider.*','erp_providerproducts.*')
																	->from('erp_provider')
																	->join('erp_providerproducts')
																	->on('erp_provider.id','=','erp_providerproducts.iproviderID')
																	->where('erp_providerproducts.iproductID','LIKE',trim($sku['sku']))
																	->where('erp_provider.state','=',2)
																	->order_by('erp_providerproducts.price')
																	->execute('erpdatabase')
																	->as_array();
// 																	
														 ?>
														<select class="input-medium" name="supplier_id[]" 
															id="supplier_<?php echo $sku['id']?>">
														<?php if($providers){
															foreach ($providers as $provider){?>
															<option value="<?php echo $provider['id']?>">
															<?php echo $provider['vProviderName']?>
															</option>															
														<?php }}?>
															</select>
														</td>
														
														<td>
														<!-- 价格 -->
														<input type="text" 
														class="input-mini" name="single_price[]" 
														id="price_<?php echo $sku['id'];?>" 
														value="<?php if($providers) echo $providers[0]['price']?>"
														disabled="disabled">
														</td>
														<td>
														<input type="text" placeholder="" 
															id="delivery_<?php echo $sku['id']?>"
															class="input-medium delivery" 
															name="delivery[]" 
															readonly="readonly"
															value="<?php echo date('Y-m-d',strtotime('+'.$sku['delivery'].'day'))?>">
														</td>
													
												</tr>
												<?php }}?>
											</table>	
											
														<?php if(isset($pagination)){echo $pagination->render();};?>

</div>
									
							

  
